package cn.edu.tjufe.llp.tin.model.bsc;

import java.time.LocalDate;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import cn.edu.tjufe.llp.tin.model.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


@Getter
@Setter
//@Builder
//@NoArgsConstructor
//@AllArgsConstructor
@Entity
@Table(name = "bsc_book", 
		indexes = {
				@Index(columnList = "name, author, deleted", name = "ux_bsc_book_name_author", unique = true) }, 
		uniqueConstraints = {
				@UniqueConstraint(columnNames = { "name", "author", "deleted" }, name = "uc_bsc_book_name_author") })
public class BscBook extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4244050565053644727L;

	@Column(nullable = false, length = 32)
	private String name;

	@Column(nullable = false, length = 32)
	private String author;

	@Column(nullable = false, length = 32)
	private String publisher;

	@Column(nullable = false)
	private LocalDate pubDate;
	
	@OneToMany(mappedBy = "book", fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
	@OrderBy("name")
	private Set<BscChapter> chapters;
}
